<?php
	
	if(!defined('APP')){
		die('error');
	}
	
	class Wx extends ApiBase  {

		//构造函数
		function __construct(){
			parent::__construct();
			$this->getDb();
		}
		
		//支付成功之后
		function paySuccessUpdateUserEWM(){
			$openid=$this->db->getval('openid');
			$uid=$this->db->getnum('uid');
			$ewmid=$this->db->getnum('ewmid');
			
			//解除二维码绑定
			$query="update ".QZ."user set ewmid=0 where id={$uid}  ";
			$this->db->idu($query);
			
			
		}
		
		//二维码页面打开后 更新用户绑定的推广码
		function updateUserEWM(){
			$ewmid=$this->db->gn('ewmid');
			$uid=$this->db->gn('uid');
			$query="update ".QZ."user set ewmid={$ewmid} where id={$uid} ";
			$this->db->idu($query);
		}
		
		//获取评论
		function getPingLun(){
			$arr=[
				[
					'id'=>1,
					'phone'=>'138****9082',
					'quyu'=>'华山 令狐冲',
					'content'=>'小师妹的鞋子以后就送这家洗，我可以练剑了！',
					'type'=>'洗鞋'
				],
				[
					'id'=>2,
					'phone'=>'137****0821',
					'quyu'=>'古龙 陆小凤',
					'content'=>'胡铁花推荐我来试试，果然屡试不爽！',
					'type'=>'洗衣'
				],
				[
					'id'=>3,
					'phone'=>'136****1022',
					'quyu'=>'金庸 李寻欢',
					'content'=>'比小李飞刀快的，只有他家骑手了，痛快！',
					'type'=>'洗鞋'
				],
				[
					'id'=>4,
					'phone'=>'134****4096',
					'quyu'=>'诗圣 杜甫',
					'content'=>'李白斗酒诗百篇，天子呼来不上船。床单洗的真洁净，月光洒落如镜面！',
					'type'=>'洗家纺'
				]
			];
			echo json_encode($arr);
		}
		
		//更新用户
		function upUserInfo(){
			$id=$this->db->gn('id');
			$nickName=$this->db->gv('nickName');
			$gender=$this->db->gv('gender');
			$avatarUrl=$this->db->gv('avatarUrl');
			$province=$this->db->gv('province');
			$city=$this->db->gv('city');
			$country=$this->db->gv('country');
			$query="update ".QZ."user set gender='{$gender}' ,
				nickName='{$nickName}' , avatarUrl='{$avatarUrl}' ,
				province='{$province}',city='{$city}' ,
				country='{$country}' where id={$id} ";
         	echo $this->db->u($query);
		}
		
		//存储用户
		function saveUser(){
			$openid=$this->db->getval('openid');
			$query="select id from ".QZ."user where openid='{$openid}' ";
			$query3="select * from ".QZ."user where openid='{$openid}' ";
			$row=$this->db->query_getrow($query);
			if($row){
				$name=$this->db->getval('name');
				$phone=$this->db->getval('phone');
				$address=$this->db->getval('address');
				$this->db->exec("update ".QZ."user set name='{$name}',phone='{$phone}',
					address='{$address}' where id='{$row['id']}' ");
			}else{
				$query2="insert into ".QZ."user (openid)values('{$openid}')  ";
				$this->db->exec($query2);
				//echo $this->db->i($query); 
			}
			$this->db->s($query3);			
		}
		
		//获取内容
		function getContentByType2(){
			$typeid=$this->db->getnum('typeid');
			$query="select * from yijiaxi_content where typeid={$typeid} and status=1 order by paixu desc   ";
			$r=$this->db->s($query);
		}
		
		
		//获取第三分类和对应数据
		function getType3(){
			$typeid=$this->db->getnum('typeid');
			$arr=[];
			$query="select id,name from yijiaxi_type where dengJi=2 and 
				status=1 and shangJiId={$typeid}";
			$r=$this->db->exec($query);
			while($row=$this->db->result_getrow($r)){
				$query2="select id,img,title,jiage,note from yijiaxi_content where 
					typeid={$row['id']}  and status=1 order by paixu desc ";
				$r2=$this->db->exec($query2);
				$item=[
					'id'=>$row['id'],
					'name'=>$row['name'],
				];
				$objs=[];
				while($obj=$this->db->result_getobj($r2)){
					$objs[]=$obj;
				}
				$item['list']=$objs;
				$arr[]=$item;
			}
			echo json_encode($arr);
		}
		
		//获取大分类
		function getBigFenLei(){
			$arr=[];
			$query="select id,name from yijiaxi_type where dengJi=0 and status=1 ";
			$r=$this->db->exec($query);
			while($row=$this->db->result_getrow($r)){
				$query2="select id,img,name from yijiaxi_type where 
					dengJi=1 and shangJiId={$row['id']} and status=1 ";
				$r2=$this->db->exec($query2);
				$item=[
					'id'=>$row['id'],
					'name'=>$row['name'],
				];
				$objs=[];
				while($obj=$this->db->result_getobj($r2)){
					$objs[]=$obj;
				}
				$item['list']=$objs;
				$arr[]=$item;
			}
			echo json_encode($arr);
		}
		
		//超级管理员登陆
		function login(){
			$username=$this->db->getval('username');
			$password=$this->db->getval('password');
			$this->query="select username,id from ".QZ."admin where 
				username='{$username}' and password='{$password}' ";
			$this->db->s($this->query);
		}
		
	}
